
<div id="playerBetReport" class="full relative">
    <h1 class="title-big-01"><?= $LANG["label"]["REPORTRESULTOFPLAYER"]; ?></h1>

    <form id="frmrefresh">
        <a href="<?php echo LODE_SERVER; ?>/View/agent-management-thongke.php?tab=historyofbet">
            <input class="button-blue-1 right" type="button" name="btnRefresh" value="<?= $LANG["label"]["VIEWALL"]; ?>"/>
        </a>
    </form>

    <form id="frmreport" class="sodedate" action="<?php echo LODE_SERVER; ?>/View/agent-management-thongke.php" method="GET">
        <input type="hidden" name="tab" value="historyofbet"/>
        <input type="hidden" name="action" value="historyofbetwithrangedate"/>
        <span><?= $LANG["label"]["FROMDAY"]; ?></span>
        <input type="text" name="datefrom" value=""/>
        <span><?= $LANG["label"]["TODAY"]; ?></span>
        <input type="text" name="dateto" value="" />
        <input class="button-blue-1" type="submit" value="<?= $LANG["label"]["VIEW"]; ?>"/>
    </form>

    <div class="table-management-1">
        <div class="row caption clear">
            <span class="no"><?= $LANG["label"]["NUMBER"]; ?></span>
            <span class="ngay"><?= $LANG["label"]["BETDAY"]; ?></span>
            <span class="firstname"><?= $LANG["label"]["FULLNAME"]; ?></span>
            <span class="loaide"><?= $LANG["label"]["TYPEOFLOTTERY"]; ?></span>
            <span class="sodanh"><?= $LANG["label"]["BETNUMBER"]; ?></span>
            <span class="tiendanh"><?= $LANG["label"]["BETMONEY"]; ?> (VNĐ)</span>
            <span class="ketqua"><?= $LANG["label"]["RESULT"]; ?></span>
            <span class="sotien"><?= $LANG["label"]["WINMONEY"]; ?></span>
        </div>

        <div class="table-management-1" id="itemContainer">
            <?php
            if (count($arr) > 0) {
                for ($i = 0; $i < count($arr); $i++) {
                    ?>
                    <div class="row clear">
                        <span title="" class="no"><?= (($start - 1) * $limit) + $i + 1 ?></span>
                        <span title="" class="ngay"><?= $arr[$i]['BetDate'] ?></span>
                        <span title="" class="firstname"><?= $arr[$i]['FirstName'] ?></span>
                        <span title="" class="loaide"><?= $arr[$i]['Loai'] . " miền " . $arr[$i]['Mien'] . " (" . $arr[$i]['Tinh'] . ")" ?></span>
                        <span title="" class="sodanh"><?= $arr[$i]['BetNumber'] ?></span>
                        <span title="" class="tiendanh"><?= number_format($arr[$i]['BetMoney'], "0", ",", ".") ?></span>
                        <span title="" class="ketqua">
                            <?php
                            if ($arr[$i]['Pendding'] != 0) {
                                if ($arr[$i]['WinTimes'] == 0)
                                    echo '<font color="#06BA52">' . $LANG["label"]["LOSE"] . '</font>';
                                else
                                    echo '<font color="#BA7D06">' . $LANG["label"]["WIN"] . '<sup>' . $arr[$i]['WinTimes'] . '</sup></font>';
                            } else
                                echo $LANG["label"]["PENDING"];
                            ?>
                        </span>
                        <span title="" class="sotien">
                            <?php
                            if ($arr[$i]['Pendding'] != 0) {
                                if ($arr[$i]['WinTimes'] == 0)
                                    echo '<font color="#06BA52">' . number_format($arr[$i]['BetMoney'], "0", ",", ".") . "&nbsp; (&uarr;)</font>";
                                else
                                    echo '<font color="#BA7D06">' . number_format($arr[$i]['BetMoney'] * $arr[$i]['WinTimes'] * $arr[$i]['WinRateBet'], "0", ",", ".") . "&nbsp; (&darr;)</font>";
                            } else
                                echo '0';
                            ?>
                        </span>
                    </div>
                <?php } ?>
            </div>

            <?php include_once '../View/templates/global/ct-paging.php'; ?>

            <?php
        } else {
            ?>
            <div class="row empty clear"><?= $LANG["label"]["NODATA"]; ?> !</div>
        <?php } ?>

    </div>

    <div id="sumaryBaoco" class="clear">
        <?php
        $noPending = 0;
        $noWin = 0;
        $noLose = 0;
        $moneyWin = 0;
        $moneyLose = 0;

        for ($i = 0; $i < count($arr); $i++) {
            if ($arr[$i]['Pendding'] == 0) {
                $noPending ++;
            } else {
                if ($arr[$i]['WinTimes'] == 0) {
                    $noLose++;
                    $moneyWin = $moneyWin + $arr[$i]['BetMoney'];
                } else {
                    $noWin++;
                    $moneyLose = $moneyLose + $arr[$i]['BetMoney'] * $arr[$i]['WinTimes'] * $arr[$i]['WinRateBet'];
                }
            }
        }
        ?>
        <div class="list-static right">
            <div>
                <span><?= $LANG["label"]["PLAYEDTOTAL"]; ?>:</span>
                <span><?php echo count($arr); ?> <?= $LANG["label"]["TIME"]; ?></span>
            </div>
            <div>
                <span><?= $LANG["label"]["NUMBEROFWONGAMES"]; ?>:</span>
                <span><?php echo $noWin; ?> <?= $LANG["label"]["TIME"]; ?></span>
            </div>
            <div>
                <span><?= $LANG["label"]["NUMBEROFLOSTGAMES"]; ?>:</span>
                <span><?php echo $noLose; ?> <?= $LANG["label"]["TIME"]; ?></span>
            </div>
            <div>
                <span><?= $LANG["label"]["NUMBEROFWAITINGGAMES"]; ?>:</span>
                <span><?php echo $noPending ?> <?= $LANG["label"]["TIME"]; ?></span>
            </div>
        </div>

        <div class="list-static right">
            <div>
                <span><?= $LANG["label"]["AMOUNTOFPLAYERWIN"]; ?>:</span>
                <span><?php echo number_format($moneyLose, "0", ",", "."); ?> VNĐ</span>
            </div>
            <div>
                <span><?= $LANG["label"]["AMOUNTOFPLAYERLOSE"]; ?>:</span>
                <span><?php echo number_format($moneyWin, "0", ",", ".") ?> VNĐ</span>
            </div>
            <div>
                <span><?= $LANG["label"]["PROFIT"]; ?>:</span>
                <span><?php echo number_format(($moneyWin - $moneyLose), "0", ",", ".") ?> VNĐ</span>
            </div>
        </div>
    </div>

    <form id="frmPrint" action="<?php echo LODE_SERVER; ?>/View/agent-management-thongke.php" method="POST" class="clear">
        <input type="hidden" name="tab" value="historyofbet"/>
        <input type="hidden" name="action" value="exportexcel"/>
        <input class="button-blue-1 right" type="submit" value="<?= $LANG["label"]["EXPORTTOEXCEL"]; ?>"/>
    </form> 

</div>

<script>
    $("#frmreport [name=datefrom]").datepicker({
        dateFormat: "dd-mm-yy",
        monthNamesShort: ["Tháng 01", "Tháng 02", "Tháng 03", "Tháng 04", "Tháng 05", "Tháng 06", "Tháng 07", "Tháng 08", "Tháng 09", "Tháng 10", "Tháng 11", "Tháng 12"],
        dayNamesMin: ["CN", "Hai", "Ba", "Tư", "Năm", "Sáu", "Bảy"],
        firstDay: 1,
        changeMonth: true,
        changeYear: true,
        numberOfMonths: 1,
        onClose: function(selectedDate) {
            $("#frmreport [name=dateto]").datepicker("option", "minDate", selectedDate);
        }
    });

    $("#frmreport [name=dateto]").datepicker({
        dateFormat: "dd-mm-yy",
        monthNamesShort: ["Tháng 01", "Tháng 02", "Tháng 03", "Tháng 04", "Tháng 05", "Tháng 06", "Tháng 07", "Tháng 08", "Tháng 09", "Tháng 10", "Tháng 11", "Tháng 12"],
        dayNamesMin: ["CN", "Hai", "Ba", "Tư", "Năm", "Sáu", "Bảy"],
        firstDay: 1,
        changeMonth: true,
        changeYear: true,
        numberOfMonths: 1,
        onClose: function(selectedDate) {
            $("#frmreport [name=datefrom]").datepicker("option", "maxDate", selectedDate);
        }
    });
</script>
